var paper = {
    editTaskPage: function (paperTaskId, paperId) {
        var url = base.basePath +"page/task/editTask.cgi";
        if (paperTaskId != null) {
            if (url.indexOf("?") == -1) {
                url += "?paperTaskId=" + paperTaskId;
            } else {
                url += "&paperTaskId=" + paperTaskId;
            }

        }
        if (paperId != null) {
            if (url.indexOf("?") == -1) {
                url += ("?paperId=" + paperId);
            } else {
                url += ("&paperId=" + paperId);
            }

        }
        console.log(url);
        index_js.appendHtmlByUrl(url);
    },
    goPaperCardPage: function (paperCardId) {
        var url = "page/paperCard/paperCard.cgi?paperCardId=" + paperCardId;
        console.log(url);
        index_js.loadRightPage(url);
    },
    addPaperCardPage: function (paperId) {
        var url = base.basePath + "page/paperCard/editPaperCard.cgi?paperId=" + paperId;
        index_js.appendHtmlByUrl(url);
    },
    editOption: function (optionId, questionId) {
        var url = base.basePath + "page/paper/editOption.cgi?optionId=" + optionId;
        if (questionId != null) {
            url += ("&questionId=" + questionId);
        }

        index_js.appendHtmlByUrl(url);
    },
    editQuestion: function (questionId, paperId) {
        var url = base.basePath + "page/paper/editQuestion.cgi";
        if (questionId != null) {
            if (url.indexOf("?") == -1) {
                url += "?questionId=" + questionId;
            } else {
                url += "&questionId=" + questionId;
            }

        }
        if (paperId != null) {
            if (url.indexOf("?") == -1) {
                url += ("?paperId=" + paperId);
            } else {
                url += ("&paperId=" + paperId);
            }

        }

        index_js.appendHtmlByUrl(url);
    },
    editPaper: function (paperId) {
        index_js.appendHtmlByUrl(base.basePath + "page/paper/editPaper.cgi?paperId=" + paperId);
    },
    checkForm: function () {
        var formObj = JWB.utils.fromSerialize($("#paperForm"));
        var flag = true;
        // if(formObj["paper.descr"] == "" ) {
        //     flag = false;
        //     $("[id=paperDescr]").parent().addClass("has-error");
        // }else {
        //     $("[id=paperDescr]").parent().removeClass("has-error");
        // }
        return flag;
    },
    goBack: function (paperId, paperCardId) {
        if (paperCardId == null || paperCardId == "") {
            index_js.loadRightPage("/page/card/card.cgi");
        } else {
            index_js.loadRightPage("/page/card/editCard.cgi?paperId=" + paperId + "&paperCardId=" + paperCardId);
        }

    },
    showFrom: function () {
        $(".showFrom").addClass("hidden");
        $(".editForm").removeClass("hidden");
    },
    editFrom: function () {
        $(".showFrom").removeClass("hidden");
        $(".editForm").addClass("hidden");
    },
    save: function () {
        if (paper.checkForm() == true) {
            var url = base.basePath + "paper/save";
            var data = JWB.utils.fromSerialize($("#paperForm"));
            $.ajax(
                {
                    url: url,
                    data: data,
                    type: "POST",
                    success: function (res) {
                        if (res.code == 0) {
                            // 成功了，跳转主页
                            var cardUrl = base.basePath +"/page/card/card.cgi";
                            index_js.loadRightPage(cardUrl);
                        } else {
                            alert(res.msg);
                        }
                    },
                    error: function (jXHR, textStatus, errorThrown) {
                        JWB.http.errorHandle(jXHR, textStatus, errorThrown);
                    }
                }
            );
        }
    }
};